const express = require('express');

const app = express();

// 解决form接受参数
app.use(express.urlencoded({ extended: false }))

app.get('/api/jsonp', (req, res) => {
  // jsonp的原理是利用script标签不受同源策略的限制

  const funName = req.query.callback;

  const data = { name: 'zs', age: 18 };

  const scriptStr = `${funName}(${JSON.stringify(data)})`;

  res.send(scriptStr);
});

app.listen(80, () => {
  console.log('Server listening on port 80');
});
